package com.eipc;

import java.util.ArrayList;
import java.util.HashMap;

import org.androidpn.sdk.Constants;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.eipc.event.OnBarClickListener;
import com.eipc.event.OnFetchOtherFinishedListener;
import com.eipc.model.Game;
import com.eipc.model.Match;
import com.eipc.model.News;
import com.eipc.model.Player;
import com.eipc.model.Score;
import com.eipc.model.SerInfoResponse;
import com.eipc.model.TSignTable;
import com.eipc.model.TSignTable.TSignTableMatch;
import com.eipc.model.Weather;
import com.eipc.util.DBHelper;
import com.eipc.util.HttpManager;
import com.eipc.util.MyLog;
import com.eipc.util.Tools;

public class SignTableActivity2 extends CommonActivity implements OnClickListener {
	public final static String[][] TURNS_SINGLE = new String[][]{ //单打轮次
		{"8"},
		{"9"},
		{"1","2"},
		{"3"},
		{"4"},
		{"5"},
		{"6"},
		{"7"},
	};
	public final static String[][] TURNS_DOUBLE = new String[][]{ //双打轮次
		{"11"},
		{"3"},
		{"5"},
		{"6"},
		{"7"},
	};
	private int mType;
	private TSignTable mDatas;
	private int mCurTurnId;
	private TextView mTitle;
	private HashMap<String, ImageButton> mCacheButtons = new HashMap<String, ImageButton>();
	private LinearLayout mLayout;
	private ImageButton mButton1;
	private ImageButton mButton2;
	private ImageButton mButton3;
	private ImageButton mButton4;
	private ImageButton mButton5;
	private ImageButton mButton6;
	private ImageButton mButton7;
	private ImageButton mButton8;
	private int[] mTurns;
	public boolean isNotRef = true;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sign_table2);
		mType = getIntent().getIntExtra("type", SignTableActivity.TYPE_SINGLE);
		initView();
	}
	
	@Override
	public void onClick(View v) {
		Integer id = (Integer)v.getTag();
		if(id!=null && id!=0){
			getData(id);
		}
	}
	
	protected void initView(){
		super.initView();
		mBar.setMiddleText(R.string.sign_table);
		mTitle = (TextView)findViewById(R.id.tv_title);
		mLayout = (LinearLayout)findViewById(R.id.layout);
		mButton1 = (ImageButton)findViewById(R.id.ib_1);
		mButton2 = (ImageButton)findViewById(R.id.ib_2);
		mButton3 = (ImageButton)findViewById(R.id.ib_3);
		mButton4 = (ImageButton)findViewById(R.id.ib_4);
		mButton5 = (ImageButton)findViewById(R.id.ib_5);
		mButton6 = (ImageButton)findViewById(R.id.ib_6);
		mButton7 = (ImageButton)findViewById(R.id.ib_7);
		mButton8 = (ImageButton)findViewById(R.id.ib_8);
		mButton1.setOnClickListener(this);
		mButton2.setOnClickListener(this);
		mButton3.setOnClickListener(this);
		mButton4.setOnClickListener(this);
		mButton5.setOnClickListener(this);
		mButton6.setOnClickListener(this);
		mButton7.setOnClickListener(this);
		mButton8.setOnClickListener(this);
		
		if(mType==SignTableActivity.TYPE_DOUBLE){//双打没有预选
			mButton1.setVisibility(View.GONE);
			mButton2.setVisibility(View.GONE);
			mButton3.setVisibility(View.GONE);
			/* 对应的轮次id */
			mButton4.setTag(1);
			mButton5.setTag(2);
			mButton6.setTag(3);
			mButton7.setTag(4);
			mButton8.setTag(5);
			
			//缓存button
			mCacheButtons.put("1", mButton4);
			mCacheButtons.put("2", mButton5);
			mCacheButtons.put("3", mButton6);
			mCacheButtons.put("4", mButton7);
			mCacheButtons.put("5", mButton8);
		}
		else{
			/* 对应的轮次id */
			mButton1.setTag(1);
			mButton2.setTag(2);
			mButton3.setTag(3);
			mButton4.setTag(4);
			mButton5.setTag(5);
			mButton6.setTag(6);
			mButton7.setTag(7);
			mButton8.setTag(8);
			
			//缓存button
			mCacheButtons.put("1", mButton1);
			mCacheButtons.put("2", mButton2);
			mCacheButtons.put("3", mButton3);
			mCacheButtons.put("4", mButton4);
			mCacheButtons.put("5", mButton5);
			mCacheButtons.put("6", mButton6);
			mCacheButtons.put("7", mButton7);
			mCacheButtons.put("8", mButton8);
		}

		mBar.setOnBarClickListener(new OnBarClickListener() {
			@Override
			public void onClickRight() {
				if(isNotRef){
					new PollingMatchScoreTask().execute();
				}
			}
			
			@Override
			public void onClickLeft() {
				Intent i = new Intent(SignTableActivity2.this, MainActivity.class);
				i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				startActivity(i);
				finish();
			}
		});
		
		updateView();
	}
	
	/*
	 * 根据数字拿到那天的数据(1--9)
	 * @param number
	 */
	private void getData(int id){
		//TODO 现在直接传去过的，可能对不上号
		
		Log.e("ID",String.valueOf(id));
		if(id==0) id = 1;
		if(id!=mCurTurnId){
			if(mType == SignTableActivity.TYPE_SINGLE)
				mDatas = mDB.getSingleSignTableData(TURNS_SINGLE[id-1]);
			else
				mDatas = mDB.getDoubleSignTableData(TURNS_DOUBLE[id-1]);
			toggleTextView(id);
			mCurTurnId = id;
			changeView();
		}
	}
	
	@Override
	protected void updateView(){
		super.updateView();
		Cursor c = mDB.queryAll(DBHelper.TB_PLAYER_GROUP);
		if(mType == SignTableActivity.TYPE_SINGLE){
			mTurns = mDB.getAllTurn(DBHelper.STATUS.MATCH_IS_GROUP_NO);
			if(mTurns!=null){
				boolean flag = false;
				int len = mTurns.length;
				int len1 = 0;
				for(int i=0;i<8;i++){
					len1 = TURNS_SINGLE[i].length;
					for(int j=0;j<len1;j++){	
						for(int k=0;k<len;k++){
							if(TURNS_SINGLE[i][j].equals(String.valueOf(mTurns[k]))){
								flag = true;
								break;
							}
						}
						if(!flag){
							mCacheButtons.get(String.valueOf(i+1)).setEnabled(false);
							mCacheButtons.get(String.valueOf(i+1)).setImageResource(getImage(i+1, 1));
						}
						else{
							flag = false;
							break;
						}
					}
				}
				getData(mCurTurnId);
			}
			else{
				for(int i=0;i<8;i++){
					mCacheButtons.get(String.valueOf(i+1)).setEnabled(false);
					mCacheButtons.get(String.valueOf(i+1)).setImageResource(getImage(i+1, 1));
				}
			}
		}
		else{
			mTurns = mDB.getAllTurn(DBHelper.STATUS.MATCH_IS_GROUP_YES);
			if(mTurns!=null){
				boolean flag = false;
				int len = mTurns.length;
				int len1 = 0;
				for(int i=0;i<5;i++){
					len1 = TURNS_DOUBLE[i].length;
					for(int j=0;j<len1;j++){	
						for(int k=0;k<len;k++){
							if(TURNS_DOUBLE[i][j].equals(String.valueOf(mTurns[k]))){
								flag = true;
								break;
							}
						}
						if(!flag){
							mCacheButtons.get(String.valueOf(i+1)).setEnabled(false);
							mCacheButtons.get(String.valueOf(i+1)).setImageResource(getImage(i+1, 1));
						}
						else{
							flag = false;
							break;
						}
					}
				}
				getData(mCurTurnId);
			}
			else{
				for(int i=0;i<5;i++){
					mCacheButtons.get(String.valueOf(i+1)).setEnabled(false);
					mCacheButtons.get(String.valueOf(i+1)).setImageResource(getImage(i+1, 1));
				}
			}
		}
	}
	
	/*
	 * 改变view
	 */
	private void changeView(){ 
		mLayout.removeAllViews();
		if(mDatas!=null){
			if(mType == SignTableActivity.TYPE_SINGLE){
				createSingleView();
			}
			else{
				createDoubleView();
			}
		}
	}
	
	/*
	 * 生成单打view
	 */
	private void createSingleView(){
		try{
			if(mDatas!=null){
				mTitle.setText(getString(R.string.sing_table_single,mDatas.count));
				View view = null;
				TextView tv = null;
				if(mDatas.matches!=null && mDatas.matches.size()>0){
					int len = mDatas.matches.size();
					TSignTableMatch match = null;
					for(int i=0;i<len;i++){
						match = mDatas.matches.get(i);
						view = mInflater.inflate(R.layout.sign_table_single_item, null);
						tv = (TextView)view.findViewById(R.id.tv_name1);
						if(match.playerA!=null){
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(match.playerA.enSname);
							else
								tv.setText(match.playerA.enSname);
							tv.setTag(match.playerA);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									showPlayerDialog((Player)v.getTag());
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_country1);
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.playerA.enCountry,match.playerA.seedNumber)));
							else
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.playerA.enCountry,match.playerA.seedNumber)));
							tv = (TextView)view.findViewById(R.id.tv_score1);
							tv.setText(match.scoreA);
						}			
						if(match.playerB!=null){
							tv = (TextView)view.findViewById(R.id.tv_name2);
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(match.playerB.enSname);
							else
								tv.setText(match.playerB.enSname);
							tv.setTag(match.playerB);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									showPlayerDialog((Player)v.getTag());
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_country2);
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.playerB.enCountry,match.playerB.seedNumber)));
							else
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.playerB.enCountry,match.playerB.seedNumber)));
							tv = (TextView)view.findViewById(R.id.tv_score2);
							tv.setText(match.scoreB);
						}			
						
						if(match.playerRetail!=null && !"".equals(match.playerRetail)){
							if(match.playerA!=null && match.playerRetail.equals(String.valueOf(match.playerA.playerId))){//A伤退
								tv = (TextView)view.findViewById(R.id.tv_status1);
								tv.setText(R.string.everyday_exit);
							}
							else{
								tv = (TextView)view.findViewById(R.id.tv_status2);
								tv.setText(R.string.everyday_exit);
							}
						}
						tv = (TextView)view.findViewById(R.id.tv_around);
						if(mLocale==LANGUAGE_CHINESE)
							tv.setText(getString(R.string.sign_table_score, match.venueCnName,match.beginTime));
						else
							tv.setText(getString(R.string.sign_table_score, match.venueEnName,match.beginTime));
						tv = (TextView)view.findViewById(R.id.tv_winner);
						if(match.winner!=null && !"".equals(match.winner)){
							if(match.playerA!=null && match.winner.equals(String.valueOf(match.playerA.playerId))){
								tv.setText(getString(R.string.sign_table_winner, mLocale==LANGUAGE_CHINESE?match.playerA.enSname:match.playerA.enSname));
							}
							else{
								tv.setText(getString(R.string.sign_table_winner, mLocale==LANGUAGE_CHINESE?match.playerB.enSname:match.playerB.enSname));
							}
						}
						mLayout.addView(view);
						if((i!=0 && i%2==1)||(i==len-1 && len%2!=0)){
							view = mInflater.inflate(R.layout.previous_next, null);
							tv = (TextView)view.findViewById(R.id.tv_previous);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									if(mCurTurnId-1>0){
										if(mCacheButtons.get(String.valueOf(mCurTurnId-1)).isEnabled())
											getData(mCurTurnId-1);
									}
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_next);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									int len = TURNS_SINGLE.length;
									if(mCurTurnId+1<len){
										if(mCacheButtons.get(String.valueOf(mCurTurnId+1)).isEnabled())
											getData(mCurTurnId+1);
									}
								}
							});
							mLayout.addView(view);
						}
					}
				}
			}
		}
		catch (Exception e) {
			Log.w("SignTableActivity2", e);
		}
	}
	
	/*
	 * 生成双打view
	 */
	private void createDoubleView(){
		try{
			if(mDatas!=null){
				mTitle.setText(getString(R.string.sing_table_double,mDatas.count));
				View view = null;
				TextView tv = null;
				if(mDatas.matches!=null && mDatas.matches.size()>0){
					int len = mDatas.matches.size();
					TSignTableMatch match = null;
					for(int i=0;i<len;i++){
						match = mDatas.matches.get(i);
						view = mInflater.inflate(R.layout.sign_table_double_item, null);
						tv = (TextView)view.findViewById(R.id.tv_name1);
						if(match.groupA!=null && match.groupA.playerA!=null){
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(match.groupA.playerA.enSname);
							else
								tv.setText(match.groupA.playerA.enSname);
							tv.setTag(match.groupA.playerA);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									showPlayerDialog((Player)v.getTag());
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_country1);
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupA.playerA.enCountry,match.groupA.playerA.seedNumber)));
							else
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupA.playerA.enCountry,match.groupA.playerA.seedNumber)));
						}
						tv = (TextView)view.findViewById(R.id.tv_name2);
						if(match.groupA!=null && match.groupA.playerB!=null){
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(match.groupA.playerB.enSname);
							else
								tv.setText(match.groupA.playerB.enSname);
							tv.setTag(match.groupA.playerB);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									showPlayerDialog((Player)v.getTag());
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_country2);
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupA.playerB.enCountry,match.groupA.playerB.seedNumber)));
							else
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupA.playerB.enCountry,match.groupA.playerB.seedNumber)));
						}
						tv = (TextView)view.findViewById(R.id.tv_name3);
						if(match.groupB!=null && match.groupB.playerA!=null){
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(match.groupB.playerA.enSname);
							else
								tv.setText(match.groupB.playerA.enSname);
							tv.setTag(match.groupB.playerA);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									showPlayerDialog((Player)v.getTag());
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_country3);
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupB.playerA.enCountry,match.groupB.playerA.seedNumber)));
							else
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupB.playerA.enCountry,match.groupB.playerA.seedNumber)));
						}
						tv = (TextView)view.findViewById(R.id.tv_name4);
						if(match.groupB!=null && match.groupB.playerB!=null){
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(match.groupB.playerB.enSname);
							else
								tv.setText(match.groupB.playerB.enSname);
							tv.setTag(match.groupB.playerB);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									showPlayerDialog((Player)v.getTag());
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_country4);
							if(mLocale==LANGUAGE_CHINESE) 
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupB.playerB.enCountry,match.groupB.playerB.seedNumber)));
							else
								tv.setText(Tools.removeClub(getString(R.string.sign_table_score, match.groupB.playerB.enCountry,match.groupB.playerB.seedNumber)));
						}
						tv = (TextView)view.findViewById(R.id.tv_score1);
						tv.setText(match.scoreA);
						tv = (TextView)view.findViewById(R.id.tv_score2);
						tv.setText(match.scoreB);
						if(match.groupRetail!=null && !"".equals(match.groupRetail)){
							if(match.groupRetail.equals(match.groupA.groupId)){//A伤退
								tv = (TextView)view.findViewById(R.id.tv_status1);
								tv.setText(R.string.everyday_exit);
							}
							else{
								tv = (TextView)view.findViewById(R.id.tv_status2);
								tv.setText(R.string.everyday_exit);
							}
						}
						tv = (TextView)view.findViewById(R.id.tv_around);
						if(mLocale==LANGUAGE_CHINESE)
							tv.setText(getString(R.string.sign_table_score, match.venueCnName,match.beginTime));
						else
							tv.setText(getString(R.string.sign_table_score, match.venueEnName,match.beginTime));
						tv = (TextView)view.findViewById(R.id.tv_winner);
						if(match.groupWinner!=null && !"".equals(match.groupWinner)){
							String str1 = "";
							String str2 = "";
							if(match.groupA!=null && match.groupWinner.equals(String.valueOf(match.groupA.groupId))){
								if(match.groupA!=null && match.groupA.playerA!=null){
									str1 = mLocale==LANGUAGE_CHINESE?match.groupA.playerA.enSname:match.groupA.playerA.enSname;
								}
								if(match.groupA!=null && match.groupA.playerB!=null){
									str2 = mLocale==LANGUAGE_CHINESE?match.groupA.playerB.enSname:match.groupA.playerB.enSname;
								}
								tv.setText(getString(R.string.sign_table_doublep_who_winner,str1,str2));
											
							}
							else{
								if(match.groupB!=null && match.groupB.playerA!=null){
									str1 = mLocale==LANGUAGE_CHINESE?match.groupB.playerA.enSname:match.groupB.playerA.enSname;
								}
								if(match.groupB!=null && match.groupB.playerB!=null){
									str2 = mLocale==LANGUAGE_CHINESE?match.groupB.playerB.enSname:match.groupB.playerB.enSname;
								}
								tv.setText(getString(R.string.sign_table_doublep_who_winner,str1,str2));
							}
						}
						mLayout.addView(view);
						if((i!=0 && i%2==1)||(i==len-1 && len%2!=0)){
							view = mInflater.inflate(R.layout.previous_next, null);
							tv = (TextView)view.findViewById(R.id.tv_previous);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									if(mCurTurnId-1>0){
										if(mCacheButtons.get(String.valueOf(mCurTurnId-1)).isEnabled())
											getData(mCurTurnId-1);
									}
								}
							});
							tv = (TextView)view.findViewById(R.id.tv_next);
							tv.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									int len = TURNS_DOUBLE.length;
									if(mCurTurnId+1<len){
										if(mCacheButtons.get(String.valueOf(mCurTurnId+1)).isEnabled())
											getData(mCurTurnId+1);
									}
								}
							});
							mLayout.addView(view);
						}
					}
				}
			}
		}
		catch (Exception e) {
			Log.w("SignTableActivity2", e);
		}
	}
	
	/*
	 * 改变头部数字的背景
	 */
	private void toggleTextView(int turnId){
		if(mCurTurnId!=turnId){
			ImageButton button = mCacheButtons.get(String.valueOf(mCurTurnId)) ;
			if(button!=null) button.setImageResource(getImage(button.getId(), 0));
			button = mCacheButtons.get(String.valueOf(turnId)) ;
			if(button!=null) button.setImageResource(getImage(button.getId(), 1));
		}
	}
	
	private int getImage(int id,int status){
		int imageId = 0;
		switch(id){
			case R.id.ib_1:
				if(status==0){//白色
					imageId = R.drawable.darw_single_01;
				}
				else{
					imageId = R.drawable.darw_single_s_01;
				}
				break;
			case R.id.ib_2:
				if(status==0){//白色
					imageId = R.drawable.darw_single_02;
				}
				else{
					imageId = R.drawable.darw_single_s_02;
				}
				break;
			case R.id.ib_3:
				if(status==0){//白色
					imageId = R.drawable.darw_single_03;
				}
				else{
					imageId = R.drawable.darw_single_s_03;
				}
				break;
			case R.id.ib_4:
				if(status==0){//白色
					imageId = R.drawable.darw_single_04;
				}
				else{
					imageId = R.drawable.darw_single_s_04;
				}
				break;
			case R.id.ib_5:
				if(status==0){//白色
					imageId = R.drawable.darw_single_05;
				}
				else{
					imageId = R.drawable.darw_single_s_05;
				}
				break;
			case R.id.ib_6:
				if(status==0){//白色
					imageId = R.drawable.darw_single_06;
				}
				else{
					imageId = R.drawable.darw_single_s_06;
				}
				break;
			case R.id.ib_7:
				if(status==0){//白色
					imageId = R.drawable.darw_single_07;
				}
				else{
					imageId = R.drawable.darw_single_s_07;
				}
				break;
			case R.id.ib_8:
				if(status==0){//白色
					imageId = R.drawable.darw_single_08;
				}
				else{
					imageId = R.drawable.darw_single_s_08;
				}
				break;
		}
		return imageId;
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			setResult(RESULT_OK);
		}
		return super.onKeyDown(keyCode, event);
	}
	
	class PollingMatchScoreTask extends CommonTask<Void>{
		public PollingMatchScoreTask(){
			super(SignTableActivity2.this);
		}
		
		private SerInfoResponse matchSir;
		private SerInfoResponse scoreSir;
		private boolean isOk = false;
		
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			//TODO 删除数据
			mDB.deleteAll(DBHelper.TB_MATCH);
			mDB.deleteAll(DBHelper.TB_SCORE);
		}
		@Override
		protected Void doInBackground(Void... params){
			isNotRef = false;
			Log.i("--"+this.getClass().getName(),"------------------PollingMatchScoreTask------------------ right : ");
			try {
				SharedPreferences sdkPreferences = getSharedPreferences(Constants.SDK_PREFERENCES, Context.MODE_PRIVATE);
				String mobileID = sdkPreferences.getString(Constants.XMPP_USERNAME,"");
				matchSir = HttpManager.loadSerInfo(getString(R.string.url_load_serinfo),mobileID,Constants.MACH,Constants.LOAD_MODEL_MATCH);
				scoreSir = HttpManager.loadSerInfo(getString(R.string.url_load_serinfo),mobileID,Constants.SCORE,Constants.LOAD_MODEL_SCORE);
				if(matchSir!=null&&scoreSir!=null){
	            	//TODO 刷新成功 等待 PUSH	
	            	try{mDB.insertMatch((Match[])matchSir.os);}catch(Exception e){mBuilder.setMessage(R.string.status_save_match_failed).setNegativeButton(R.string.btn_close, null).show();}
	            	try{mDB.insertScore((Score[])scoreSir.os);}catch(Exception e){mBuilder.setMessage(R.string.status_save_score_failed).setNegativeButton(R.string.btn_close, null).show();}
	            	new FetchOtherTask(SignTableActivity2.this, mDB, new OnFetchOtherFinishedListener() {	
						@Override
						public void OnFinished(ArrayList<News> news, Game game, Weather weather) {
							if(news!=null && news.size()>0){
								for(News n : news){
									mInfos.addView(getNewsView(n));
									mInfos.startFlipping();
								}
							}
							else{
								mInfos.addView( mInflater.inflate(R.layout.news_item, null));
							}
							mBottomBar.setGame(game);
							mBottomBar.setWeather(weather);
							mBottomBar.startFlipper();
						}
					}).execute(mLocale);
	            	isOk = true;
	            }
			} catch (Exception e) {
				MyLog.error(FetchConsultService.class,"",e);
			}
			return null;
		}
		
		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);
			isNotRef = true;
			if(!isOk){
				mBuilder.setMessage(R.string.status_connect_failed).setNegativeButton(R.string.btn_close, null).show();
			}else{
				updateView();
			}
		}
		
	}
}
